package com.htc.android.footprints.view;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.htc.android.footprints.utils.FootprintUtils;
import com.htc.android.footprints.vo.Footprint;

public class Snapshot extends LinearLayout
{
  private static final String TAG = "Snapshot";
  private TextView mAddress = null;
  private TextView mDateTime = null;
  private ImageView mFootprintImage = null;
  private TextView mLatitude = null;
  private TextView mLongitude = null;
  private TextView mPhone = null;
  private LinearLayout mPostcardPreview = null;
  private RatingBar mRatingBar = null;
  private Bitmap mSnapshot = null;
  private TextView mTitle = null;

  public Snapshot(Context paramContext)
  {
    super(paramContext);
    initView();
  }

  public Snapshot(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    initView();
  }

  private byte[] bitmapToByteArray(Bitmap paramBitmap)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(paramBitmap.getRowBytes());
    byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
    paramBitmap.compress(Bitmap.CompressFormat.JPEG, 80, localByteArrayOutputStream);
    return arrayOfByte;
  }

  private Bitmap decodeJpeg(String paramString)
  {
    return null;
  }

  private void initView()
  {
    addView((ViewGroup)((LayoutInflater)getContext().getSystemService("layout_inflater")).inflate(2130903078, null));
    this.mPostcardPreview = ((LinearLayout)findViewById(postcard_preview));
    this.mFootprintImage = ((ImageView)findViewById(2131493019));
    this.mTitle = ((TextView)findViewById(2131493020));
    this.mDateTime = ((TextView)findViewById(2131493021));
    this.mPhone = ((TextView)findViewById(2131493022));
    this.mLatitude = ((TextView)findViewById(2131493024));
    this.mLongitude = ((TextView)findViewById(2131493025));
    this.mAddress = ((TextView)findViewById(2131493026));
    this.mRatingBar = ((RatingBar)findViewById(2131493023));
    this.mFootprintImage.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
      }
    });
  }

  private void saveBitmapToJpeg(Bitmap paramBitmap)
  {
    String str = Environment.getExternalStorageDirectory().getAbsolutePath() + "/footprints/thumbnails";
    Object localObject = null;
    try
    {
      FileOutputStream localFileOutputStream = new FileOutputStream(new File(str + "/snapshot.jpg"));
      localObject = localFileOutputStream;
      paramBitmap.compress(Bitmap.CompressFormat.JPEG, 80, localObject);
      return;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
        localFileNotFoundException.printStackTrace();
    }
  }

  private void saveByteArrayToSD(String paramString, byte[] paramArrayOfByte)
  {
    String str = Environment.getExternalStorageDirectory().getAbsolutePath() + "/footprints/thumbnails";
    try
    {
      FileOutputStream localFileOutputStream = new FileOutputStream(new File(str + "/" + paramString));
      localFileOutputStream.write(paramArrayOfByte);
      localFileOutputStream.flush();
      localFileOutputStream.close();
      return;
    }
    catch (Exception localException)
    {
      while (true)
        Log.e("Snapshot", localException.toString());
    }
  }

  public Bitmap getSnapshot()
  {
    int i = this.mPostcardPreview.getHeight();
    int j = this.mPostcardPreview.getWidth();
    this.mPostcardPreview.getTop();
    Bitmap localBitmap = Bitmap.createBitmap(j, i, Bitmap.Config.RGB_565);
    drawChild(new Canvas(localBitmap), this.mPostcardPreview, System.currentTimeMillis());
    return localBitmap;
  }

  public void initPostcard(Footprint paramFootprint)
  {
    if (paramFootprint.mPicPath != null)
    {
      Drawable localDrawable = Drawable.createFromPath(paramFootprint.mPicPath);
      if (localDrawable != null)
        this.mFootprintImage.setBackgroundDrawable(localDrawable);
    }
    this.mTitle.setText(paramFootprint.mName);
    String str1 = new SimpleDateFormat(getContext().getResources().getString(2131361875)).format(new Date(paramFootprint.mCreateTime));
    this.mDateTime.setText(str1);
    this.mPhone.setText(paramFootprint.mTel);
    String str2 = FootprintUtils.getFormatedLat(paramFootprint.mLatitude);
    String str3 = FootprintUtils.getFormatedLon(paramFootprint.mLongitude);
    this.mLatitude.setText(str2);
    this.mLongitude.setText(str3);
    this.mAddress.setText(paramFootprint.mAddr);
    this.mRatingBar.setRating(paramFootprint.mRate);
    invalidate();
  }

  public void takeSnapshot()
  {
    saveBitmapToJpeg(getSnapshot());
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.view.Snapshot
 * JD-Core Version:    0.6.0
 */